package com.google.code.p.restrpc.core.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ProfilingInterceptor implements MethodInterceptor {
    
    private static final Log logger = LogFactory.getLog(DebugInterceptor.class);
    
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        long currentTimeMillis = System.nanoTime();
        try {
            return methodInvocation.proceed();
        }
        finally {
            long duration = System.nanoTime() - currentTimeMillis;
            if (logger.isDebugEnabled()) {
                logger.debug(methodInvocation.toString() + " duration:"
                             + duration
                             + " nano seconds");
            }
        }
    }
    
}
